package com.wanghua.mall.order.controller;

import com.wanghua.common.utils.PageUtils;
import com.wanghua.common.utils.R;
import com.wanghua.mall.order.entity.OrderEntity;
import com.wanghua.mall.order.service.OrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;


/**
 * 订单
 *
 * @author wanghua
 * @email 2367279431@qq.com
 * @date 2021-09-07 17:09:01
 */
@RestController
@RequestMapping("/order/order")
public class OrderController {

    @Resource
    private OrderService orderService;


    /**
     * 根据订单号获取订单状态
     *
     * @param orderNo 订单号
     * @return
     */
    @GetMapping("/getOrderStatus/{orderNo}")
    public R getOrderStatus(@PathVariable("orderNo") String orderNo) {
        Integer status = orderService.getOrderStatus(orderNo);
        return R.ok().put("data", status);
    }


    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = orderService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 查询某个用户的订单列表
     */
    @PostMapping("/listWithItem")
    public R listWithItem(@RequestBody Map<String, Object> params) {
        PageUtils page = orderService.queryPageWithItem(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        OrderEntity order = orderService.getById(id);
        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody OrderEntity order) {
        orderService.save(order);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody OrderEntity order) {
        orderService.updateById(order);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        orderService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
